import java.io.*;
//文件的复制
public class CopyFileDemo {
    public static void main(String[] args) {
        try {
            copyFile("F:\\1.png","F:\\2.png");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void copyFile(String src,String dist) throws IOException {
        FileInputStream in = new FileInputStream(src);
        FileOutputStream out = new FileOutputStream(dist);
        byte[] buffer = new byte[20*1024];// read() 最多读取 buffer.length 个字节// 返回的是实际读取的个数// 返回 -1 的时候表示读到 eof，即文件尾
        int cnt;
        while ((cnt = in.read(buffer,0,buffer.length)) != -1){
            out.write(buffer,0,cnt);
        }
        in.close();
        out.close();
    }
}
